package poker;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Scanner;

import javax.swing.JButton;
import javax.swing.JPanel;

import enums.ActionType;

public class Human extends Player implements ActionListener
{
	
	GameRound gameRound;
	JPanel playerButtons;
	ActionType chosenActionType;
	boolean haveChosenAction;
	String actionString;
	
	public Human(int startCash, String name) 
	{
		super(startCash, name);
		setIsAI(false);
		chosenActionType = null;
		playerButtons  = new JPanel();
		playerButtons.setPreferredSize(new Dimension(200, 200));
		addButtons();
	}

	public JPanel getButtons(){ return playerButtons;}
	
	public void addButtons()
	{		
		GridLayout gridLayout = new GridLayout(3,2);
		playerButtons.setLayout(gridLayout);

		JButton fold = new JButton("Fold");
		fold.addActionListener(this);
		
		JButton call = new JButton("Call");
		JButton check = new JButton("Check");	

		JButton minRaise = new JButton("Raise 100");
		JButton medRaise = new JButton("Raise 200");
		JButton highRaise = new JButton("Raise 300");

		playerButtons.add(fold);
		playerButtons.add(call);
		playerButtons.add(check);
		playerButtons.add(minRaise);
		playerButtons.add(medRaise);
		playerButtons.add(highRaise);
	}
	
	
	@Override
	public ActionType chooseAction(GameRound gameRound)
	{	
		haveChosenAction = false;
		ArrayList<ActionType> legalActions = Rules.getLegalActions(this);
		Printer.printAvailbleActions(this, legalActions);
		Printer.printValueToCall(this, gameRound.getCurrentBet() - getPostedCash());
		
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		chosenActionType = legalActions.get(input);		
		
		return chosenActionType;			
	}

	//TODO: Gj�r noe fornuftig med click events
	@Override
	public void actionPerformed(ActionEvent e) {
		
		if (e.getActionCommand().equals("Fold")) 
		{
			haveChosenAction = true;
			System.out.println("Fold");
			chosenActionType = ActionType.FOLD;
		}
		
	}
}
